# !/usr/bin/env python
# -*- coding:utf-8 -*-
# 
# __author__ = 'Yangqihui'

import time,onewire,ds18x20
from machine import Pin

class T18B20:
    def __init__(self,pn=4):
        self.ow = onewire.OneWire(Pin(pn))
        self.ds = ds18x20.DS18X20(self.ow)
        self.roms = self.ds.scan()

    def get(self):
        self.ds.convert_temp()
        time.sleep_ms(750)
        for rom in self.roms:
            temp = self.ds.read_temp(rom)
        return temp